package com.netty.study.handler;

import com.alibaba.fastjson.JSONObject;
import com.netty.study.dto.UserMessage;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.MessageToMessageEncoder;

import java.util.List;

public class MessageToStringEncoderHandler extends MessageToMessageEncoder<UserMessage> {

    @Override
    protected void encode(ChannelHandlerContext channelHandlerContext, UserMessage userMessage, List<Object> list) throws Exception {
        String message = JSONObject.toJSONString(userMessage);
        list.add(message);
    }
}